package com.a0soft.gphone.aTruffleHog.wnd.info;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Patrick Cheng <patrick.taiwan (at) gmail.com>
 *
 */

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.a0soft.gphone.aTruffleHog.R;
import com.a0soft.gphone.aTruffleHog.di.DeviceInfo;
import com.a0soft.gphone.aTruffleHog.di.DeviceInfoKey;
import com.a0soft.gphone.aTruffleHog.util.CONSTS;

public class InfoURView {
    private static final String UR_KEYS[] = {
            //DeviceInfoKey.K.UR_ID,	// do not show this information for user.
            DeviceInfoKey.K.UR_LANG,
            DeviceInfoKey.K.UR_LANG_REGION,
            DeviceInfoKey.K.UR_COUNTRY
    };

    private Context _cxt = null;
    private DeviceInfo _di = null;
    
    public
    InfoURView(Context cxt, DeviceInfo di)
    {
    	_cxt = cxt;
    	_di = di;
    }
    
    public View
    getView(boolean for_preview)
    {
        LinearLayout sv = new LinearLayout(_cxt);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        sv.setLayoutParams(params);
        sv.setOrientation(LinearLayout.VERTICAL);
        
        int childno = 0;
        for (int i=0; i<UR_KEYS.length; i++) {
            String info = _di.GetString(UR_KEYS[i]);
            if (!TextUtils.isEmpty(info) && !info.equals(CONSTS.UNAVAILABLE)) {
                View row = LayoutInflater.from(_cxt).inflate(R.layout.info_item,null);
                InfoItemViewWrapper wrapper = new InfoItemViewWrapper(row);
                row.setTag(wrapper);
                wrapper.setItemName(DeviceInfoKey.GetName(UR_KEYS[i]));
                wrapper.setItemDetail(info);
                sv.addView(row);
                childno++;
            }               
        }
        return sv;
    }
}
